package com.camelot.ccr.global.util;

import java.security.MessageDigest;

/**
 * 
 * <pre>
 * 工资加密、解密算法工具类
 * </pre>
 * @author donghuijun
 * @version V0.1, 2014-1-8 下午6:58:27
 */
public class EncyptUtil {
	
	public static final String TEPASSWORD ="111111"; 	//te初始密码
	/**
	 * 
	 * <pre>
	 * 加密
	 * </pre>
	 * @param inStr 输入字符串
	 * @return 字符串
	 * @author donghuijun, 2014-1-8 下午6:59:05
	 */
	public static String KL(String inStr) {
		if(inStr==null){
			return null;
		}else{
			char[] a = inStr.toCharArray();
			for (int i = 0; i < a.length; i++) {
				a[i] = (char) (a[i] ^ 't');
			}
			String secret = new String(a);
			return secret;			
		}
	}

	/**
	 * 
	 * <pre>
	 * 解密
	 * </pre>
	 * @param inStr 解密前的字符串
	 * @return	解密后的字符串
	 * @author donghuijun, 2014-1-8 下午7:02:14
	 */
	public static String JM(String inStr) {
		if(inStr==null){
			return null;
		}else{
			char[] a = inStr.toCharArray();
			for (int i = 0; i < a.length; i++) {
				a[i] = (char) (a[i] ^ 't');
			}
			String secret1 = new String(a);
			return secret1;			
		}
	}
	
	
	/**
	 * 
	 * <pre>
	 * MD5加密算法
	 * </pre>
	 * @param password 加密的字符串
	 * @return 加密后的字符串
	 * @author donghuijun, 2014-1-8 下午7:00:12
	 */
	public static String MD5(String password) {
		MessageDigest messageDigest = null;
		try {
			messageDigest = MessageDigest.getInstance("MD5");

			messageDigest.reset();

			messageDigest.update(password.getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		byte[] byteArray = messageDigest.digest();
		StringBuffer md5StrBuff = new StringBuffer();
		for (int i = 0; i < byteArray.length; i++) {
			if (Integer.toHexString(0xFF & byteArray[i]).length() == 1){
				md5StrBuff.append("0").append(
						Integer.toHexString(0xFF & byteArray[i]));
			}else{
				md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
			}
		}
		return md5StrBuff.toString().trim();
	}
	/**
	 * 
	 * <pre>
	 * 测试加密解密
	 * </pre>
	 * @param args 输入
	 * @author donghuijun, 2014-1-8 下午7:01:50
	 */
	public static void main(String []args){
		System.out.println(KL("10000"));
	}
}
